package special;

public class Solution2 {
    class ListNode{
        int key;
        int value;
        ListNode next;
        public ListNode(){

        }
        public ListNode(int key, int value){
            this.key = key;
            this.value = value;
        }
    }
    public LRUcache getCache(){
        return new LRUcache();
    }
    public class LRUcache{
        ListNode[] table = new ListNode[100];

        public LRUcache() {
        }

        int get(int key){
            int index = key % 100;
            ListNode cur = table[index];
            while(cur != null){
                if (cur.key == key){
                    return cur.value;
                }
                cur = cur.next;
            }
            return -1;
        }
        void put(int key, int value){
            int index = key % 100;
            ListNode root = table[index];
            if(root == null){
                table[index] = new ListNode(key, value);
                return;
            }
            ListNode cur = root;
            while(cur != null){
                if(cur.key == key){
                    cur.value = value;
                    return;
                }
                cur = cur.next;
            }
            cur.next = new ListNode(key, value);
        }
    }

    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        LRUcache cache = solution2.getCache();
        cache.put(7,10);
        cache.put(7,11);
        cache.put(7,12);
        int val = cache.get(7);
        int val2 = cache.get(8);
        System.out.println(val2);
    }
}
